package com.example.springapplicationdemo.exceptionhandler;

import com.example.springapplicationdemo.vo.RestResVo;
import com.example.springapplicationdemo.exceptionhandler.exception.UserException;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.*;

@Order(-10001)
@RestControllerAdvice(annotations = RestController.class)// 指定Advice应用于RestController注解
public class UserRestControllerAdvice {
    /**
     * ControllerAdvice中的ExceptionHandler会对ControllerAdvice作用域中的Controller生效
     * @param e
     * @return
     */
    @ExceptionHandler
//    @ResponseBody  在RestControllerAdvice中，无须添加@ResponseBody，RestControllerAdvice中已添加@ResponseBody注解
    public RestResVo<Void> handleUserException(UserException e){
        return RestResVo.error(e);
    }
}
